//
//  MiddleView.m
//  DemoTest
//
//  Created by DaShuEdu on 2017/4/24.
//  Copyright © 2017年 DaShuEdu. All rights reserved.
//

#import "MiddleView.h"

@interface MiddleView ()

@property (nonatomic) UIColor *color;

@end

@implementation MiddleView

- (instancetype)initWithNewColor:(UIColor *)color
{
    if (self = [super init]) {
        self.color = color;
        NSLog(@"%s",__func__);
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        NSLog(@"%s",__func__);
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        NSLog(@"%s",__func__);
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
    
    NSLog(@"%s",__func__);
    //为view上面的两个角做成圆角
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.bounds;
    maskLayer.path = maskPath.CGPath;
    self.layer.mask = maskLayer;
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 20)];
    label.text = @"Hello Label";
    label.backgroundColor = self.color;
    [self addSubview:label];
    
    
}

- (void)layoutSubviews {
    NSLog(@"%s",__func__);
    self.backgroundColor = [UIColor redColor];
    
//    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 20)];
//    label.text = @"Hello Label";
//    label.backgroundColor = [UIColor yellowColor];
//    [self addSubview:label];
}

//- (void)setNeedsDisplay {
//    NSLog(@"%s",__func__);
//}

@end
